const path = require('path');
const Timestamp = new Date().getTime();
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
    publicPath: './',
    assetsDir: 'static',
    productionSourceMap: false,
    lintOnSave: process.env.NODE_ENV !== 'production',
    devServer: { // 开发服务器配置
        historyApiFallback: false,
        noInfo: false,
        host: "localhost",
        contentBase: './',
        hot: true,
        inline: true,
        watchOptions: {
            // 忽略监视的文件或目录
            ignored: ['node_modules'],
            aggregateTimeout: 600
        },
        overlay: { // 这里配置 html 页面是否显示 eslint 错误信息蒙版
            errors: true,
            warnings: true
        }
    },
    pluginOptions: {
        "style-resources-loader": {
            preProcessor: "scss",
            patterns: [
                path.resolve(__dirname, "./src/assets/styles/mixin.scss"),
            ]
        }
    },
    configureWebpack: config => {
        config.resolve.alias['vue$'] = 'vue/dist/vue.esm.js';
        // if (process.env.NODE_ENV === 'production') {
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
            return {
                plugins: [new CompressionPlugin({
                    test: /\.js$|\.css/,
                    threshold: 10240,
                    minRatio: 0.8,
                    deleteOriginalAssets: false
                })],
                output: { // 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
                    filename: `[name].${process.env.VUE_APP_VERSION}.${Timestamp}.js`,
                    chunkFilename: `[name].${process.env.VUE_APP_VERSION}.${Timestamp}.js`
                }
            };
        // }
    }
};
